package com.ruoyi.project.wenyanwen.word.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wenyanwen.word.domain.IkWord;
import com.ruoyi.project.wenyanwen.word.service.IIkWordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 自定义分词Controller
 * 
 * @author shixiangwen
 * @date 2020-08-25
 */
@Controller
@RequestMapping("/wenyanwen/word")
public class IkWordController extends BaseController
{
    private String prefix = "wenyanwen/word";

    @Autowired
    private IIkWordService ikWordService;

    @RequiresPermissions("wenyanwen:word:view")
    @GetMapping()
    public String word()
    {
        return prefix + "/word";
    }

    /**
     * 查询自定义分词列表
     */
    @RequiresPermissions("wenyanwen:word:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IkWord ikWord)
    {
        startPage();
        List<IkWord> list = ikWordService.selectIkWordList(ikWord);
        return getDataTable(list);
    }

    /**
     * 导出自定义分词列表
     */
    @RequiresPermissions("wenyanwen:word:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IkWord ikWord)
    {
        List<IkWord> list = ikWordService.selectIkWordList(ikWord);
        ExcelUtil<IkWord> util = new ExcelUtil<IkWord>(IkWord.class);
        return util.exportExcel(list, "word");
    }

    /**
     * 新增自定义分词
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存自定义分词
     */
    @RequiresPermissions("wenyanwen:word:add")
    @Log(title = "自定义分词", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IkWord ikWord)
    {
        return toAjax(ikWordService.insertIkWord(ikWord));
    }

    /**
     * 修改自定义分词
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IkWord ikWord = ikWordService.selectIkWordById(id);
        mmap.put("ikWord", ikWord);
        return prefix + "/edit";
    }

    /**
     * 修改保存自定义分词
     */
    @RequiresPermissions("wenyanwen:word:edit")
    @Log(title = "自定义分词", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IkWord ikWord)
    {
        return toAjax(ikWordService.updateIkWord(ikWord));
    }

    /**
     * 删除自定义分词
     */
    @RequiresPermissions("wenyanwen:word:remove")
    @Log(title = "自定义分词", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ikWordService.deleteIkWordByIds(ids));
    }
}
